﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using MySql.EntityFrameworkCore.Metadata;

#nullable disable

namespace Repository.Migrations
{
    /// <inheritdoc />
    public partial class init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ShortAnswer",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Answer = table.Column<string>(type: "longtext", nullable: true),
                    ShortAnswerQId = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ShortAnswer", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "longtext", nullable: false),
                    Password = table.Column<string>(type: "longtext", nullable: false),
                    BonusPoints = table.Column<int>(type: "int", nullable: false),
                    IsAdmin = table.Column<bool>(type: "tinyint(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SurveyTmplate",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "longtext", nullable: false),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    Reward = table.Column<int>(type: "int", nullable: false),
                    UserId = table.Column<Guid>(type: "char(36)", nullable: true),
                    Created = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    FillNumer = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SurveyTmplate", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SurveyTmplate_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "Users",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ChoiceQuestion",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    IsMutipleChoice = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    SurveyId = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChoiceQuestion", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChoiceQuestion_SurveyTmplate_SurveyId",
                        column: x => x.SurveyId,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "CompletedSurvey",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    CompletedTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    SurveyId = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CompletedSurvey", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CompletedSurvey_SurveyTmplate_Id",
                        column: x => x.Id,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_CompletedSurvey_SurveyTmplate_SurveyId",
                        column: x => x.SurveyId,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ShortAnswerQs",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    SurveyId = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ShortAnswerQs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ShortAnswerQs_SurveyTmplate_SurveyId",
                        column: x => x.SurveyId,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Choice",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    IsChecked = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    ChoiceQId = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Choice", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Choice_ChoiceQuestion_ChoiceQId",
                        column: x => x.ChoiceQId,
                        principalTable: "ChoiceQuestion",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ChoiceAnswers",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    Answer = table.Column<int>(type: "int", nullable: false),
                    ChoiceQId = table.Column<int>(type: "int", nullable: false),
                    ChoiceQId1 = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChoiceAnswers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChoiceAnswers_ChoiceQuestion_ChoiceQId1",
                        column: x => x.ChoiceQId1,
                        principalTable: "ChoiceQuestion",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Choice_ChoiceQId",
                table: "Choice",
                column: "ChoiceQId");

            migrationBuilder.CreateIndex(
                name: "IX_ChoiceAnswers_ChoiceQId1",
                table: "ChoiceAnswers",
                column: "ChoiceQId1");

            migrationBuilder.CreateIndex(
                name: "IX_ChoiceQuestion_SurveyId",
                table: "ChoiceQuestion",
                column: "SurveyId");

            migrationBuilder.CreateIndex(
                name: "IX_CompletedSurvey_SurveyId",
                table: "CompletedSurvey",
                column: "SurveyId");

            migrationBuilder.CreateIndex(
                name: "IX_ShortAnswerQs_SurveyId",
                table: "ShortAnswerQs",
                column: "SurveyId");

            migrationBuilder.CreateIndex(
                name: "IX_SurveyTmplate_UserId",
                table: "SurveyTmplate",
                column: "UserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Choice");

            migrationBuilder.DropTable(
                name: "ChoiceAnswers");

            migrationBuilder.DropTable(
                name: "CompletedSurvey");

            migrationBuilder.DropTable(
                name: "ShortAnswer");

            migrationBuilder.DropTable(
                name: "ShortAnswerQs");

            migrationBuilder.DropTable(
                name: "ChoiceQuestion");

            migrationBuilder.DropTable(
                name: "SurveyTmplate");

            migrationBuilder.DropTable(
                name: "Users");
        }
    }
}
